package com.yunji.web.coupon;

import com.google.common.collect.Sets;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.utils.ExcelUtil;
import com.yunji.coupon.business.CouponBusiness;
import com.yunji.coupon.dto.CouponListDTO;
import com.yunji.coupon.dto.CouponPageDTO;
import com.yunji.coupon.enums.CouponStatusEnum;
import com.yunji.coupon.vo.CouponVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author : peter-zhu
 * @date : 2024/10/25 18:28
 * @description : TODO
 **/
@Api(tags = "优惠券")
@RestController
@RequestMapping("/coupon")
public class CouponController {
    @Resource
    private CouponBusiness couponBusiness;
//
//    @ApiOperation("系统弹窗自动领取优惠券")
//    @GetMapping("/systemReceiveList/{triggerDic}")
//    public Response<List<CouponVO>> systemReceiveList(@PathVariable String triggerDic) {
//        return ResponseHelper.success(couponBusiness.systemAutoReceive(triggerDic));
//    }
//
//    @ApiOperation("下单时最优惠的优惠券")
//    @GetMapping("/getOptimalCoupon")
//    public Response<OptimalCouponVO> getOptimalCoupon(@RequestBody OptimalCouponDTO dto) {
//        return ResponseHelper.success(couponBusiness.getOptimalCoupon(dto));
//    }
//
////    @ApiOperation("下单时优惠券列表(含有最优策略的优惠券ID和金额)")
////    @GetMapping("/unReceiveList")
////    public Response<List<CouponVO>> unReceiveList() {
////        return ResponseHelper.success(couponBusiness.getUnReceiveList());
////    }
//
//    @ApiOperation("下单时未使用优惠券列表(过滤网点并让用户选择优惠券)")
//    @GetMapping("/unUsedSelectList/{siteId}")
//    public Response<UseCouponVO> unUsedSelectList(@PathVariable Long siteId) {
//        return ResponseHelper.success(couponBusiness.unUsedSelectList(siteId));
//    }
//
//    @ApiOperation("下单后未领取优惠券列表")
//    @GetMapping("/unReceiveList")
//    public Response<List<CouponVO>> unReceiveList() {
//        return ResponseHelper.success(couponBusiness.getUnReceiveList());
//    }
//
//    @ApiOperation("下单后根据模板ID领取优惠券")
//    @PutMapping("/create/{couponTmplId}")
//    public Response<List<CouponVO>> createByTmplId(@PathVariable Long couponTmplId) {
//        return ResponseHelper.handle(couponBusiness.receiveAvailableCoupon(couponTmplId), "领取失败");
//    }

    @ApiOperation("平台用户优惠券列表-可用(未使用且未失效)")
    @GetMapping("/unUsedList")
    public Response<List<CouponVO>> unUsedList() {
        CouponListDTO dto = new CouponListDTO();
        dto.setStatusList(Sets.newHashSet(CouponStatusEnum.UN_USED.getCode()));
        return ResponseHelper.success(couponBusiness.couponList(dto));
    }

    @ApiOperation("平台用户优惠券列表-无效(失效,已使用)")
    @GetMapping("/invalidList")
    public Response<List<CouponVO>> invalidList() {
        CouponListDTO dto = new CouponListDTO();
        dto.setStatusList(Sets.newHashSet(CouponStatusEnum.INVALID.getCode(), CouponStatusEnum.USED.getCode()));
        return ResponseHelper.success(couponBusiness.couponList(dto));
    }

    @ApiOperation("后台优惠券列表(分页)")
    @PostMapping("/receiveList")
    public Response<List<CouponVO>> receiveList(@RequestBody CouponPageDTO dto) {
        return ResponseHelper.successWithPage(couponBusiness.couponPageList(dto), dto.getTotal());
    }

    @ApiOperation("后台优惠券列表(导出)")
    @PostMapping("/exportList")
    public void exportList(@RequestBody CouponPageDTO dto, HttpServletResponse response) {
        List<CouponVO> voList = couponBusiness.couponList(dto);
        ExcelUtil<CouponVO> util = new ExcelUtil<>(CouponVO.class);
        util.exportExcel(response, voList, "优惠券列表");
    }
}
